import {onMounted, ref,  reactive, computed } from 'vue';
import { hiprint, defaultElementTypeProvider } from"vue-plugin-hiprint";
export default function importConfig() {
    const base = reactive<any>({
        visible: false,
        spinning: true,
        waitShowPrinter: false,
        // 纸张宽 mm
        width: 0,
        // 模板
        hiprintTemplate: {},
        // 数据
        printData: {}
    })

    const hideModal = () => {
        base.visible = false
    }


    const show = (hiprintTemplate, printData, width = '210') => {
        base.visible = true
        base.spinning = true
        base.width = hiprintTemplate.editingPanel ? hiprintTemplate.editingPanel.width : width;
        base.hiprintTemplate = hiprintTemplate
        base.printData = printData
        console.log(hiprintTemplate);
        setTimeout(() => {
          // eslint-disable-next-line no-undef
          $('#preview_content_design').html(hiprintTemplate.getHtml(printData))
          base.spinning = false
        }, 500)
    }

    const print = () => {
        base.waitShowPrinter = true
        base.hiprintTemplate.print(base.printData, {}, {
            callback: () => {
                console.log('callback')
                base.waitShowPrinter = false
            }
        })
    }

    const toPdf = () => {
        base.hiprintTemplate.toPdf({}, '打印预览');
    }
    return {
        base,
        hideModal,
        show,
        print,
        toPdf,

    }
}